package com.qiaofei.exception;

import com.qiaofei.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)//捕获所有异常
    public Result ex(Exception ex){
        ex.printStackTrace();
        System.out.println(ex.getClass().toGenericString());
        if(ex.getClass().toString().equals("class org.springframework.dao.DataIntegrityViolationException")){
            return Result.error("请检查是否有未填写的内容");
        }
        return Result.error("对不起,操作失败,请联系管理员");
    }

}

